﻿Imports System.Reflection
Imports System.Windows.Forms

Public Class HardwarePorts
    Implements UCBase.I_Plugin
    Private DevList As New List(Of UCBase.UCSDevice)
    Public Function GetDevice(ByVal Name As String) As System.Windows.Forms.Control Implements UCBase.I_Plugin.GetDevice
        If Name.Contains("SerialPort:") Then
            Dim X As New SerialPort
            X.Port = Name.Substring(Name.IndexOf(":") + 1)
            Return X
        End If
        If Name = "SerialPort" Then Return New SerialPort
        If Name = "UCNet" Then Return New UCNet
        If Name = "ComMonitor" Then Return New ComMonitor
        If Name = "UCNetTester" Then Return New UCNetTester
        Return Nothing
    End Function
    Public Sub New()
        'Add Control to plugin Device List
        DevList.Add(New UCBase.UCSDevice("UCNet Transcoder", "UCNet", "Ports", "UCNetTranscoder"))
        DevList.Add(New UCBase.UCSDevice("UCNet Tester", "UCNetTester", "Ports", "UCNetTester"))
        DevList.Add(New UCBase.UCSDevice("Coms Monitor", "ComMonitor", "Ports", "ComMonitor"))
        DevList.Add(New UCBase.UCSDevice("Serial Port", "SerialPort", "Ports", "Serial Port", False))

        Dim Ports As String() = IO.Ports.SerialPort.GetPortNames
        Dim Port As String
        For Each Port In Ports
            DevList.Add(New UCBase.UCSDevice("Serial Port : " & Port, "SerialPort:" & Port, "Ports", "Serial Port : " & Port))
        Next Port

    End Sub
    Public ReadOnly Property Devices() As System.Collections.Generic.List(Of UCBase.UCSDevice) Implements UCBase.I_Plugin.Devices
        Get
            Return DevList
        End Get
    End Property
    Public Sub Unload() Implements UCBase.I_Plugin.Unload
        Me.Finalize()
    End Sub
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
    Public WriteOnly Property Resources() As UCBase.ResourceManager Implements UCBase.I_Plugin.Resources
        Set(ByVal value As UCBase.ResourceManager)

        End Set
    End Property
End Class
